package com.iwhalecloud.bss.kite.cucc.web.service.accept.handler.attr;

import com.iwhalecloud.bss.kite.client.api.scene.operate.IOperateSceneCommonService;
import com.iwhalecloud.bss.kite.client.vo.scene.CommonAttrVO;
import com.iwhalecloud.bss.kite.common.constant.KeyConsts;
import com.iwhalecloud.bss.kite.common.util.KiteStringUtils;
import com.iwhalecloud.bss.kite.manager.api.IQuerySceneInstService;
import com.iwhalecloud.bss.kite.manager.inst.KiteAttr;
import com.iwhalecloud.bss.kite.manager.inst.KiteSceneInst;
import com.iwhalecloud.bss.kite.web.context.KiteWebContext;
import com.iwhalecloud.bss.kite.web.service.accept.attr.handler.AbstractAttrHandler;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @Classname CheckWayInternetHandler
 * @Description 核查方式
 *     国际互联网，页面不展示，默认传：2-快速并行核查
 * @Author zhang.song
 * @Date 2022-03-31 10:16
 */
@Service
public class CheckWayInternetHandler extends AbstractAttrHandler {

    @Autowired
    private IQuerySceneInstService querySceneInstService;

    @Autowired
    private IOperateSceneCommonService operateSceneCommonService;

    @Override
    public void init(CommonAttrVO commonAttr) {
        String sceneInstId = KiteWebContext.getContextNew().getCurrentSceneInstId();
        KiteSceneInst kiteSceneInst = querySceneInstService.getSceneInst(sceneInstId);
        String offerId = querySceneInstService.getOfferInst(kiteSceneInst.getCustId(), kiteSceneInst.getRootInstId()).getOfferId();

        // 国际互联网，不展示核查方式，默认传：2-快速并行核查
        if(KiteStringUtils.isEqual(offerId, "50040853")) {
            commonAttr.setShowType(KeyConsts.PROD_ATTR_SHOW_TYPE_H);
            commonAttr.setValue("2");
            commonAttr.setValueDesc("快速并行核查");
        }

        KiteAttr checkTypeAttr = querySceneInstService.getCommonAttr(sceneInstId, commonAttr.getFieldName());
        if(checkTypeAttr != null) {
            checkTypeAttr.setShowType(commonAttr.getShowType());
            checkTypeAttr.setValue(commonAttr.getValue());
            checkTypeAttr.setValueDesc(commonAttr.getValueDesc());
            operateSceneCommonService.setCommonAttr(sceneInstId, checkTypeAttr);
        }
    }
}
